<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>书籍分类</title>
    <!-- 直接复用你原来的样式表 -->
    <link rel="stylesheet" href="navT.css">
    <link rel="stylesheet" href="comm.css">
    <link rel="stylesheet" href="midSite.css">
    <style>
        @import url("category.css");
    </style>
</head>

<body>
    <!-- 分类标题 -->
    <div class="cat-header">书籍分类</div>

    <!-- 分类按钮 -->
    <div class="cat" id="cat"></div>

    <!-- 书籍列表 -->
    <div class="books" id="books"></div>

    
    <div style="text-align:center;margin:30px 0;">
        <button class="btn-sm" onclick="location.href='index.html'">返回主页</button>
    </div>
    <!-- 直接用你主页的购物车脚本 -->
    <script type="module">
        const CART_KEY = 'myCart';
        function getCart() { try { return JSON.parse(localStorage.getItem(CART_KEY)) || []; } catch { return []; } }
        function addCartItem(item) { const list = getCart(); list.push(item); localStorage.setItem(CART_KEY, JSON.stringify(list)); }
        window.addCart = function (id, name, price, img) {
            addCartItem({ id, name, price, img: img || 'placeholder-封面', qty: 1 });
            alert('已加入购物车！');
        };
    </script>
</body>

</html>
<script src="category.js"></script>